package cn.edu.sgu.www.mhxysy.controller.partner;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.partner.PartnerSkillDTO;
import cn.edu.sgu.www.mhxysy.vo.treegrid.PartnerSkillTreeGrid;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.partner.PartnerSkillService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "助战技能管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/partner_skill", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class PartnerSkillController {

    private final PartnerSkillService partnerSkillService;

    @Autowired
    public PartnerSkillController(PartnerSkillService partnerSkillService) {
        this.partnerSkillService = partnerSkillService;
    }

    @ApiOperation("分配助战技能")
    @RequestMapping(value = "/distribute", method = RequestMethod.POST)
    public JsonResult<Void> distribute(PartnerSkillDTO partnerSkillDTO) {
        partnerSkillService.distribute(partnerSkillDTO);

        return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
    }

    @ApiOperation("删除助战技能")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "skillId", value = "助战技能ID", required = true),
            @ApiImplicitParam(name = "partnerId", value = "助战ID", required = true)
    })
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public JsonResult<Void> delete(
            @NotNull(message = "助战技能类型" + CustomMessages.ID_NOT_NULL) Integer skillId,
            @NotNull(message = "助战" + CustomMessages.ID_NOT_NULL) Integer partnerId) {
        partnerSkillService.delete(skillId, partnerId);

        return JsonResult.success(CustomMessages.DELETE_SUCCESS);
    }

    @ApiOperation("查询助战技能类型ID列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "技能类型", required = true),
            @ApiImplicitParam(name = "partnerId", value = "助战ID", required = true)
    })
    @RequestMapping(value = "/selectSkillIds", method = RequestMethod.GET)
    public JsonResult<List<Integer>> selectSkillIds(
            @NotNull(message = "技能类型" + CustomMessages.NOT_NULL) Integer type,
            @NotNull(message = "助战" + CustomMessages.ID_NOT_NULL) Integer partnerId) {
        List<Integer> list = partnerSkillService.selectSkillIds(type, partnerId);

        return JsonResult.success(null, list);
    }

    @ApiOperation("获取助战技能树")
    @RequestMapping(value = "/listTree", method = RequestMethod.GET)
    public JsonResult<List<PartnerSkillTreeGrid>> listTree(
            @ApiParam(name = "partnerId", value = "助战ID", required = false)
            @RequestParam(required = false) Integer partnerId) {
        List<PartnerSkillTreeGrid> list = partnerSkillService.listTree(partnerId);

        return JsonResult.success(null, list);
    }

}